package com.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.mvc.model.Student;
@Controller
public class StudentController {
	
	@RequestMapping("/student")
	public ModelAndView student() {
		return new ModelAndView("student", "command", new Student());
	}
	
	@RequestMapping(value="/addStudent", method=RequestMethod.POST)
	public String addStudent(@ModelAttribute("studentForm") Student student, 
			   ModelMap model) {
		model.addAttribute("name", student.getName());
		model.addAttribute("id", student.getId());
		model.addAttribute("age", student.getAge());
		return "result";
	}
}
